package com.example.demo01.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.demo01.R;
import com.example.demo01.demo.AlertDialogDemo;
import com.example.demo01.demo.BroadcastDemo;
import com.example.demo01.demo.FragmentDemo;
import com.example.demo01.demo.GridViewDemo;
import com.example.demo01.demo.HandlerMessageDemo;
import com.example.demo01.demo.HttpDemo;
import com.example.demo01.demo.IntentDemo;
import com.example.demo01.demo.ListViewDemo;
import com.example.demo01.demo.PopupDemo;
import com.example.demo01.demo.PreferenceDemo;
import com.example.demo01.demo.RequestPermissionsDemo;
import com.example.demo01.demo.ServiceDemo;
import com.example.demo01.demo.SpinnerDemo;
import com.example.demo01.demo.lifeCycleDemo;
import com.example.demo01.utils.ToastUtil;

//! 这里继承 AppCompatActivity 是为了兼容老版本Android，继承这个后顶部会显示蓝紫色标题应用名称
//! 并且蓝紫色标题栏可以在 AndroidManifest.xml 文件里修改对应属性，如 label、icon、theme等
public class MainActivity extends AppCompatActivity {

    //! 这里也可以直接继承 Activity
//public class MainActivity extends Activity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EdgeToEdge.enable(this);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        initView();
    }

    //. 初始化控件
    private void initView() {
        //. ListView示例
        findViewById(R.id.btn_lv_demo).setOnClickListener(v -> toPages(ListViewDemo.class));
        //. GridView示例
        findViewById(R.id.btn_gv_demo).setOnClickListener(v -> toPages(GridViewDemo.class));
        //. Spinner下拉框
        findViewById(R.id.btn_s_demo).setOnClickListener(v -> toPages(SpinnerDemo.class));
        //. PopupWindow示例
        findViewById(R.id.btn_popup_demo).setOnClickListener(v -> toPages(PopupDemo.class));
        //. AlertDialog示例
        findViewById(R.id.btn_alert_dialog_demo).setOnClickListener(v -> toPages(AlertDialogDemo.class));
        //. Intent跳转示例
        findViewById(R.id.btn_it_demo).setOnClickListener(v -> toPages(IntentDemo.class));
        //. Activity生命周期示例
        findViewById(R.id.btn_lc_demo).setOnClickListener(v -> toPages(lifeCycleDemo.class));
        //. Service示例
        findViewById(R.id.btn_service_demo).setOnClickListener(v -> toPages(ServiceDemo.class));
        //. BroadcastDemo广播接收器示例(未实现)
        findViewById(R.id.btn_BroadcastDemo_demo).setOnClickListener(v -> toPages(BroadcastDemo.class));
        //. Handler消息传递机制示例
        findViewById(R.id.btn_handler_message_demo).setOnClickListener(v -> toPages(HandlerMessageDemo.class));
        //. Fragment示例
        findViewById(R.id.btn_fragment_demo).setOnClickListener(v -> toPages(FragmentDemo.class));
        //. HttpDemo示例
        findViewById(R.id.btn_http_demo).setOnClickListener(v -> toPages(HttpDemo.class));
        //. 请求权限示例
        findViewById(R.id.btn_request_permissions_demo).setOnClickListener(v -> toPages(RequestPermissionsDemo.class));
        //. Preference示例
        findViewById(R.id.btn_preference_demo).setOnClickListener(v -> toPages(PreferenceDemo.class));
    }


    //. 跳转页面
    private void toPages(Class<?> cls) {
        Intent intent = new Intent(this, cls);
        startActivity(intent);
    }

}